package com.lfg.leetcode.leetcode0;


import java.util.*;

public class No17LetterCombinations {
    private static Map<Character, String[]> data = new HashMap<Character, String[]>();

    static {
        data.put('2', new String[]{"a", "b", "c"});
        data.put('3', new String[]{"d", "e", "f"});
        data.put('4', new String[]{"g", "h", "i"});
        data.put('5', new String[]{"j", "k", "l"});
        data.put('6', new String[]{"m", "n", "o"});
        data.put('7', new String[]{"p", "q", "r", "s"});
        data.put('8', new String[]{"t", "u", "v"});
        data.put('9', new String[]{"w", "x", "y", "z"});
    }

    public static List<String> letterCombinations(String digits) {
        List<String> ret = new ArrayList<>();
        if (digits.length() == 0) {
            return ret;
        }
        for (int i = 0; i < digits.length(); i++) {
            char key = digits.charAt(i);
            List<String> tmp = new ArrayList<>();
            String[] list = data.get(key);
            if (list == null) {
                continue;
            }
            if (ret.size() == 0) {
                tmp.addAll(Arrays.asList(list));
            } else {
                for (String s : ret) {
                    for (String a : list) {
                        tmp.add(s + a);
                    }
                }
            }
            ret = tmp;
        }

        return ret;
    }


    public static void main(String[] args) {
        System.out.println(letterCombinations("123"));
//        System.out.println(threeSum(new int[]{-1,0,1,2,-1,-4}));
//        System.out.println(threeSum(new int[]{-2,0,0,2,2}));
    }
}
